<%@ page contentType="text/html;charset=utf-8" language="java" 
	import="java.sql.*, java.io.File, java.util.Arrays, java.util.Comparator,
	git.bankview.sl.db.DBConnectionFactory, git.bankview.sl.db.DBUtil" 
%><%@ taglib uri="/WEB-INF/tld/struts-bean.tld" prefix="bean" 
%><%@ taglib uri="/WEB-INF/tld/struts-html.tld" prefix="html" 
%><%@ taglib uri="/WEB-INF/tld/struts-logic.tld" prefix="logic" 
%><%@ taglib uri="/WEB-INF/tld/struts-nested.tld" prefix="nested" 
%><%@ include file="/jsp/inc/pageUtils.jsp"
%><jsp:useBean id="oLogon" class="git.bankview.wl.bean.LogonBean" scope="session" />
<!-- jsp:useBean id="oNavigate" class="git.bankview.wl.bean.TransNavigateBean" / -->
<%
	System.out.println("bbbbbbAAAAAAAAAAAAAAAAAa");
	request.setCharacterEncoding("iso8859_1");
	String transid = request.getParameter("transid");
	int labelorder = Integer.parseInt(transid);

	//git.bankview.wl.auth.UserAuth.validate(oLogon, transid, 1);
	boolean bOwner = true; //git.bankview.wl.auth.UserAuth.validateMethod(oLogon, transid, 255);
	boolean bUpdater = true; //git.bankview.wl.auth.UserAuth.validateMethod(oLogon, transid, 13);

	//oNavigate.setTransid(transid);
	String translabel = null;
	String transfunc = null;
	
	Connection conn = DBConnectionFactory.getCoreConnection();
	try
	{
		Statement st = conn.createStatement();
		try
		{
			ResultSet rs = st.executeQuery("select * from infotrans where transid = '" + transid + "'");
			try
			{
				if (!rs.next())
					throw new SQLException("�����Ѿ���ɾ��" + transid);
				
				translabel = rs.getString("translabel").trim();
				transfunc = rs.getString("transfunc").trim();
			}
			finally
			{
				rs.close();
			}
		}
		finally
		{
			st.close();
		}
	}
	finally
	{
		conn.close();
	}
	
	if (!"UPLOADED".equals(transfunc))
	{
		throw new java.lang.IllegalArgumentException("Illegal argument: " + transfunc);
	}
	
	String appRoot = application.getRealPath("/WEB-INF/pub/");
	File transDir = new File(appRoot + "/" + transid);
	if (!transDir.exists())
		transDir.mkdirs();
	
	String[] list = transDir.list();
	Arrays.sort(list, new Comparator() {
		public int compare(Object o1, Object o2)
		{
			return ((String)o2).compareTo((String)o1);
		}
	});
%>
<html>
<head>
	<meta http-equiv=content-type content="text/html; charset=GBK">
	<title>ChinaRE MIS - <%=translabel%></title>
	<link rel="stylesheet" href="../../style/default_aux.css">
	<link rel="stylesheet" href="../../style/pp.css">
</head>
<body onload="oninit();">
	<script src="../../script/overlib.js" language="JavaScript"></script>
	<script src="../../script/style.js" language="JavaScript"></script>
	<script src="../../script/windows.js" language="JavaScript"></script>
	<script src="../../script/lajax.js" language="JavaScript"></script>
	<table width="100%" height="100%">
		<tr height="32px"><td>
			<table width="100%"><tr><td width="70%" nowrap ><b><%=translabel %> </b></td>
			<td nowrap><a id="oExcelUrl" href="#"><img src="../../images/excels.gif" title="����Excel�ļ�..."></a></td>
			<td><form id="oViewForm" action="<%=request.getContextPath()%>/jsp/upload/UploadReportDownload.jsp" target="viewer"
			><input type="hidden" name="transid" value="<%=transid%>"><select name="file" onchange="if ('' != this.value) { oViewForm.submit(); };">
<%
	for (int i = 0; i < list.length; ++i)
	{
		System.out.println(list[i]);

		String fn = list[i]; //new String(list[i].getBytes("iso8859_1"), "utf-8");
		System.out.println(fn);
		int ppos = fn.lastIndexOf('.');
		if (0 < ppos)
		{
		String title = fn.substring(0, ppos);
%>				<option value="<%=fn %>" <% if (0 == i) { %>selected<% } %> ><%=title %></option>
<%
		}
	}
%>				</select></form>
				</td><% if (bUpdater) { %><form action="UploadReport.jsp" target="viewer" method="post" enctype="multipart/form-data"><td width="100px"><input type="file" name="uploadFile"
				></td><td width="32px" nowrap ><input type="image" src="../../images/upload.gif"></td><td><input type="hidden" value="<%=transid %>" name="transid"></td></form>
				<% } %><% if (bOwner) { %><td nowrap>
				</td><% } %></tr></table>
		</td></tr>
		<tr><td><iframe id="oViewer" src="about:blank" name="viewer" frameborder="0" width="100%" height="100%"
			onload="oExcelUrl.href = '<%=request.getContextPath()%>/jsp/upload/UploadReportDownload.jsp?transid=<%=transid%>&file=' + oViewForm.file.value + '&ext=xls'; "
		></iframe>
		</td></tr>
	</table>
	
<script language="javascript"><!--
function oninit()
{
	if ("" != oViewForm.file.value)
		oViewForm.submit();
}
function onFormSubmit()
{
	return false;
}
--></script>

</body>
</html>

